package com.straw.hat.com.straw.hat.jdk.concurrent.executor;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * company: 鲸灵科技
 * author: qiyue@webuy.ai
 * date: 2019/9/28
 * time: 9:59 PM
 */
public class MaxThreadCountStudy {

    public static final ThreadPoolExecutor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
            1, 3, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1));

    /**例如核心线程数为2 队列为10 ,最大线程数为 20,13个线程来的*/
    public static void main(String[] args) {
        for (int i = 0; i< 10; i++) {
            THREAD_POOL_EXECUTOR.execute(new RunClzz());
        }
    }

    static class RunClzz implements Runnable {

        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("thread name : "+Thread.currentThread().getName());
        }
    }
}
